package com.ff.dao;

import static com.ff.mapper.WaresDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import java.util.List;
import java.util.Optional;

import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ff.mapper.WaresMapper;
import com.ff.model.Wares;

@Repository
public class WaresDao {
	@Autowired
	private WaresMapper wmapper;
	public void setWmapper(WaresMapper wmapper) {
		this.wmapper = wmapper;
	}
	public List<Wares> select_() {//查询所有水果
		SelectStatementProvider ssp=select(wmapper.selectList)
				.from(wares)
				.build()
				.render(RenderingStrategies.MYBATIS3);
			List<Wares> opt=wmapper.selectMany(ssp);
			return opt!=null?opt:null;
	}
	public List<Wares> select_limit(int id2, int cnt1) {//分页查询水果
		SelectStatementProvider ssp=select(wmapper.selectList)
				.from(wares)
				.limit(cnt1).offset(id2)
				.build()
				.render(RenderingStrategies.MYBATIS3);
		List<Wares> opt=wmapper.selectMany(ssp);
		return opt!=null?opt:null;
	}
	public int insert11(Wares f) {//添加
		return wmapper.insert(f);
	}
	public Wares find11(int id) {//id查询水果
		SelectStatementProvider s=select(wmapper.selectList)
				.from(wares)
				.where(wid,isEqualTo(id))
				.build()
				.render(RenderingStrategies.MYBATIS3);
		Optional<Wares> opt=wmapper.selectOne(s);
		return opt.isPresent()?opt.get():null;
	}
	public int update11(Wares f) {//修改
		UpdateStatementProvider usp=update(wares)
				.set(wname).equalTo(f.getWname())
				.set(recommendation).equalTo(f.getRecommendation())
				.set(wprice).equalTo(f.getWprice())
				.set(winventory).equalTo(f.getWinventory())
				.set(fsell).equalTo(f.getFsell())
				.where(wid,isEqualTo(f.getWid()))
				.build()
				.render(RenderingStrategies.MYBATIS3);
		int i=wmapper.update(usp);
		return i;
	}
	public int delete01(int id) {//删除
		return wmapper.deleteByPrimaryKey(id);
	}
	
	public List<Wares> findffname(String fusername1) {//模糊查询水果
		SelectStatementProvider s=select(wmapper.selectList)
									.from(wares)
									.where(wname,isLikeCaseInsensitive("%"+fusername1+"%"))
									.build()
									.render(RenderingStrategies.MYBATIS3);
		List<Wares> l=wmapper.selectMany(s);
		return l!=null?l:null;
	}
}
